<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=none" />
		<title>信息通过查询</title>
		<link rel="stylesheet" href="./css/base.css" />
		<link rel="stylesheet" href="./iconfont/iconfont.css" />
		<link rel="stylesheet" href="./css/vant@2.12.54.css" />
		<link rel="stylesheet" href="./css/inquire.css" />
		<style>
			#app {
				width: 100%;
				height: 100vh;
				overflow: hidden;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<div class="logo">
				<img src="./img/Logo.png" alt="" />
			</div>
			<div class="box">
				<div class="sousuo">通过</div>
				<p class="f20 fwb">输入卡号查询发货信息</p>
				<input type="text" placeholder="输入卡号" v-model="cardnumber" />
				<div class="searchBox">
					<button v-show="placeAnOrderBtnShow" class="placeAnOrder btn" @click="placeAnOrder()">
						下单
					</button>
					<button class="search btn" @click="search()">点击搜索</button>
				</div>

				<p class="f16 mt-20 red" v-if="visible">{{message}}</p>
				<p class="copyright">德龙农业版权所有</p>
			</div>
		</div>
	</body>
	<script src="./js/vue@2.7.14.js"></script>
	<script src="./js/axios@1.5.0.min.js"></script>
	<script src="./js/vant@2.12.54.min.js"></script>
	<script src="./js/request.js"></script>
	<script>
		new Vue({
			el: "#app",

			data: function() {
				return {
					cardnumber: "",
					visible: false,
					message: "",
					placeAnOrderBtnShow: false,
				};
			},
			mounted() {
				this.cardnumber = sessionStorage.getItem("account");
				console.log(this.cardnumber);
				const token = sessionStorage.getItem("token");
				const url = baseUrl + "/user.order/getInfo";
				if (!token) {
					console.log(111);
					window.location.href = "login.html";
				}
				this.init(token, url);
			},
			methods: {
				placeAnOrder() {
					window.location.href = "submit.html";
				},
				search() {
					const account = this.cardnumber;
					if (!account || account == '') {
						this.$toast("请输入卡号")
						return
					}

					const url = baseUrl + "/user.order/getExpressNo";
					const token = sessionStorage.getItem("token");


					axios({
						url: url,
						method: "post",
						params: {
							app_id: 10001,
							token: token,
							account: account,
						},
					}).then((res) => {
						if (res.data.code == 1) {
							console.log(res.data);

							if (
								res.data.data.express_company == "" ||
								res.data.data.express_no == ""
							) {
								// this.$toast.fail("已审核，未发货");
								this.message = "已审核，未发货";
								this.visible = true;
								setTimeout(() => {
									this.visible = false;
								}, 2000);
							} else {
								sessionStorage.setItem("account", account);
								window.location.href = "./expressage.html?id=" + account;
							}
						} else {
							this.$toast.fail("卡号错误，请重新输入");
						}
					});
				},
				async init(token, url) {
					const res = await axios({
						url: url,
						method: "post",
						params: {
							app_id: 10001,
							token: token,
						},
					});
					if (res.data.data.num > 0) {
						this.placeAnOrderBtnShow = true;
					}
				},
			},

			activated() {
				this.cardnumber = sessionStorage.getItem("account");
			},
			//   beforeDestroy(){
			// 	location.reload();
			//   }
		});
		Vue.use(vant);
	</script>
</html>